/* 
 * @description: 图片组件
 * @author: Jane 
 * @date: 2023-09-13 16:58:33
 */
import 'package:basic_common/common_config.dart';
import 'package:basic_common/common_exports.dart';
import 'package:flutter_svg/flutter_svg.dart';

/// 圆形头像
Widget circleImg({String head = '', double width = 40, double raduis = 50}) {
  String defHead = CommonConfig.defaultUrl;
  return Container(
    width: ScreenHelper.width(width),
    height: ScreenHelper.width(width),
    //超出部分，可裁剪
    clipBehavior: Clip.antiAlias,
    decoration: BoxDecoration(
      borderRadius: BorderRadius.circular(raduis),
    ),
    child: Image.network(
      head.isEmpty ? defHead : head,
      fit: BoxFit.fill,
      errorBuilder: (context, error, stackTrace) {
        return Image.asset(
          "assets/sign/logo.png",
          width: ScreenHelper.width(width),
          height: ScreenHelper.width(width),
          package: "basic_common",
        );
      },
    ),
  );
}

/// svg图片
Widget svgImage(
    {required String assets,
    double width = 16,
    AlignmentGeometry alignment = Alignment.center,
    String? package,
    ColorFilter? colorFilter}) {
  return SvgPicture.asset(assets,
      width: ScreenHelper.width(width),
      height: ScreenHelper.width(width),
      alignment: Alignment.center,
      package: package,
      colorFilter: colorFilter);
}

/// 加载网络图片
Widget netWorkImgBox({required String netPath}) {
  String defImg =
      "https://desk-fd.zol-img.com.cn/t_s960x600c5/g6/M00/03/0E/ChMkKWDZLXSICljFAC1U9uUHfekAARQfgG_oL0ALVUO515.jpg";
  return Container(
    //使用加载loading作为占位图
    child: CachedNetworkImage(
      imageUrl: netPath.isEmpty ? defImg : netPath,
      progressIndicatorBuilder: (context, url, downloadProgress) =>
          CircularProgressIndicator(value: downloadProgress.progress),
      errorWidget: (context, url, error) => Icon(Icons.error),
    ),
  );
}
